import Vue from 'vue';
import ElementUI from 'element-ui';
import CurdTablePlugin from 'curd-table';
import '@/assets/layout.scss';
import permissions from '@/mixin/permissions';
import { registerAppEnter } from 'micro-frontend-app-hooks';

Vue.mixin(permissions);

Vue.prototype.$baseUrl = process.env.VUE_APP_BASE_API;

Vue.use(ElementUI);
Vue.use(CurdTablePlugin);

Vue.config.productionTip = false;

const isDev = process.env.NODE_ENV === 'development';

if (isDev) {
  localStorage.token = process.env.VUE_APP_TOKEN;
  // eslint-disable-next-line global-require
  require('element-ui/lib/theme-chalk/index.css');
  require('antd/dist/antd.css');
  require('@/assets/dev-container.scss');

  if (!process.env.VUE_APP_CURD_TABLE_PATH) {
    require('curd-table/dist/curd-table.css');
  }
} else {
  // hack for require('curd-table/dist/curd-table.css');
  require.context('../../node_modules/curd-table/dist', false, /\.css$/);
}

export function mountApp(App, store, router) {
  const vm = new Vue({
    store,
    router,
    render: h => h(App),
    mounted() {
      this.$router.push({ name: 'index' });
    }
  }).$mount('#app');

  registerAppEnter(vm);

  return vm;
}
